<?php
namespace app\home\logic;
class OrderLogic {
	public static function addGoodsOrder(){
		$user_id = session("user_info.id");
		$data = \app\common\model\Cart::with("goods,spec_goods")->where("user_id",$user_id)->where("is_selected",1)->select();
		$data = (new \think\Collection($data))->toArray();
		$totle_number = 0; # 数量
		$totle_price = 0; # 总价
		foreach($data as $k => $v){
			if(!empty($v["spec_goods_id"])){
				$data[$k]["goods"]["goods_price"] = $v["spec_goods"]["price"]; # 价格
				$data[$k]["goods"]["goods_number"] = $v["spec_goods"]["store_count"];# 数量
				$data[$k]["goods"]["frozen_number"] = $v["spec_goods"]["store_frozen"];# 冻结库存数量
				$data[$k]["goods"]["cost_price"] = $v["spec_goods"]["cost_price"]; # 成本价格
			}
			// dump($v);die;
			$totle_number += $v["number"]; # 数量
			$totle_price += $v["number"] * $v["goods"]["goods_price"]; # 使用数理 * 以 价格
		}
		$res = [
			"totle_number" => $totle_number,
			"totle_price"  => $totle_price,
			"data" 			=> $data
		];
		return $res;

	}
}